package com.example.personalizededucationsystem.repository;

import com.example.personalizededucationsystem.model.ErrorNotebook;
import com.example.personalizededucationsystem.model.Question;
import com.example.personalizededucationsystem.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface ErrorNotebookRepository extends JpaRepository<ErrorNotebook, Long> {

    Optional<ErrorNotebook> findByStudentAndQuestion(User student, Question question);

    List<ErrorNotebook> findByStudent(User student);

    @Query("SELECT DISTINCT e FROM ErrorNotebook e JOIN e.question.knowledgePoints kp WHERE e.student = :student AND kp.subject = :subjectName")
    List<ErrorNotebook> findByStudentAndSubjectName(@Param("student") User student, @Param("subjectName") String subjectName);

}